import { createRouter, createWebHashHistory } from 'vue-router'
// import Home from '../views/home/Home'
// import Shop from '../views/shop/Shop'
// import Login from '../views/login/Login'
// import Plugin from '../views/plugin/Plugin'

const routes = [
  {
    path: '/',
    name: 'Home',
    // component: Home,
    component: () => import(/* webpackChunkName: "home" */ '../views/home/Home'),
    alias: '/home'
  },
  {
    path: '/shop',
    name: 'Shop',
    // component: Shop,
    component: () => import(/* webpackChunkName: "shop" */ '../views/shop/Shop'),
    alias: '/shop'
  },
  {
    path: '/plugin',
    name: 'Plugin',
    // component: Plugin,
    component: () => import(/* webpackChunkName: "plugin" */ '../views/plugin/Plugin'),
    alias: '/plugin'
  },
  {
    path: '/login',
    name: 'Login',
    // component: Login,
    component: () => import(/* webpackChunkName: "login" */ '../views/login/Login'),
    beforeEnter: (to, from, next) => {
      const { isLogin } = localStorage
      isLogin ? next({ name: 'Home' }) : next()
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  const { isLogin } = localStorage;
  (isLogin || to.name === 'Login') ? next() : next({ name: 'Login' })
})

export default router
